// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CImplActionInsert.
//   $Id$


#pragma once
class CXFormsParseInsert;
class CImplBind;
#include "actions.h"
class INodeset;
#include "ImplActionWithOnDemandBindingsAndOutOfLineContext.h"
#include "PointerContainer.h"

class CXFormsElementInsert;
class CImplActionInsert : public CImplActionWithOnDemandBindingsAndOutOfLineContext
{
	friend class CXFormsParseInsert;
public:
	CImplActionInsert();
	CImplActionInsert(CXFormsElementInsert *);
protected:
	virtual void ResolveBindings();
private:
	CComBSTR m_sNodeset;
	CComBSTR m_sAt;
	CComBSTR m_sPosition;
	CComBSTR m_sBind;
	CComBSTR m_sOrigin;
	virtual HRESULT PerformAction();
	HRESULT GetNodeToInsert(IXMLDOMNode * pContext,CImplBind * pBind,IXPathResult * pResult, IXMLDOMNode ** ppNodeToInsert);
	HRESULT GetRelatedNode(CImplBind * pBind,IXPathResult* pResult,IXMLDOMNode ** pRelatedNode);
	HRESULT InsertNode(IXMLDOMNode * pContext,IXMLDOMNode * pNodeToInsert,IXMLDOMNode *pRelatedNode);
//new XForms 1.1 pattern.
	HRESULT DetermineInsertContext(IXMLDOMNode * pEvaluationContext,IXMLDOMNode ** pInsertContext);
	HRESULT DetermineNodeSetBindingNodeset(IXMLDOMNode * pInsertContext,CPointerContainer<INodeset> & pNodesetBindingNodeset);
	HRESULT DetermineOriginNodeset(IXMLDOMNode * pInsertContext,INodeset * pNodesetBindingNodeset,CPointerContainer<INodeset>& pOriginNodeset);
	HRESULT DetermineInsertLocationNode(IXMLDOMNode * pInsertContext,INodeset * pNodesetBindingNodeset,IXMLDOMNode ** pInsertLocationNode);
	HRESULT CopyOriginToTarget(INodeset * pOriginNodeset,INodeset * pNodesetBindingNodeset, IXMLDOMNode * pInsertLocationNode);
	HRESULT NotifyCompletion();
};